package user.zc.action;

import user.zc.action.comp.ManagerAction;
import user.zc.controller.ISystemConfig;
import user.zc.vo.ColumnDTO;

import javax.swing.table.DefaultTableModel;
import java.util.List;

public class ManagerSystemDefaultColumnAction extends ManagerAction<ColumnDTO> {
    private ISystemConfig systemConfigController;
    public ManagerSystemDefaultColumnAction(ISystemConfig systemConfigController) {
        super(new String[]{"名称","类型","备注","主键"}, (dto)->{
            try {
                systemConfigController.delete(dto.getKey());
            } catch (Exception e) {
                e.printStackTrace();
            }
        },  (dto,callback)->{
            new AddOrUpdateSystemDefaultColumnAction(systemConfigController,dto,(value)->{
                //成功的画，需要重新刷新
                callback.accept(true);
            });
        });
        this.systemConfigController = systemConfigController;
        setTitle("系统默认列管理");
        refresh();
    }

    @Override
    protected List<ColumnDTO> refreshRow(DefaultTableModel tableModel) throws Exception{
        List<ColumnDTO> columnDTOS = systemConfigController.list();
        columnDTOS.forEach(dto->{
            tableModel.addRow(new Object[]{dto.getKey(),dto.getType(),dto.getComment(),dto.getIsPk()});
        });
        return columnDTOS;
    }
}
